package com.github.lzyzsd.jsbridge.example;

import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;
import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;

/**
 * <pre>
 * Description: 获取web端提交的信息
 * Copyright  : Copyright (c) 2022
 * Email      : jusenr@163.com
 * Author     : Jusenr
 * Date       : 2022/1/27 10:05
 * Project    ：JsBridge-1.0.4
 * PackageName：com.github.lzyzsd.jsbridge.example.
 * </pre>
 */
public class SubmitFromWeb extends BaseBindHandler {
    private static final SubmitFromWeb info = new SubmitFromWeb();

    private SubmitFromWeb() {
    }

    public static SubmitFromWeb getInstance() {
        return info;
    }

    @Override
    public void bindHandler(BridgeWebView webView) {
        webView.registerHandler("submitFromWeb", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                Log.i(TAG, "registerHandler handler = submitFromWeb, data from web = " + data);
                function.onCallBack("submitFromWeb exe, response data 中文 from Java");
                ToastUtils.showShort("JS返回: %s", data);
            }
        });
    }
}
